/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package 解析.node.node;

import java.io.Serializable;
import java.util.ArrayList;
import 解析.node.others.TreeInfo;
import 解析.Matcher;
import 解析.Pattern;

/**
 *
 * @author yanxi
 */
public class Node extends Object implements Serializable{ 
    private static final long serialVersionUID = 1000;
    public Node next; 
            
    public transient ArrayList<Node> children=new ArrayList<Node>();
    public transient String 节点类型; 
    
    public Node() {
        next = Pattern.accept; 
        //System.out.println(this.getClass().getName());
    } 
    
    
    public ArrayList<Node> getChildren(){return children;}
    //public HashMap<String, PropertyAbstract属性> getAtts(){return atts;}
    
    public void printTree(String s){
        System.out.println(s+toString()+"    next:"+next.toString());
        //if(next!=null)next.printTree(s);
    }
    
    @Override
    public String toString(){
        return "["+this.getClass().getName()+"]";
    }

    //This method implements the classic accept node./
    public boolean match(Matcher matcher, int i, CharSequence seq) {
        matcher.last = i;
        matcher.groups[0] = matcher.first;
        matcher.groups[1] = matcher.last;
        return true;
    }

    //This method is good for all zero length assertions. 
    public boolean study(TreeInfo info) {
        if (next != null) {
            return next.study(info);
        } else {
            return info.deterministic;
        }
    }
    
    public String getRegexString(){return "<<"+this.getClass().getName()+">>";}
}
